// 此文件用于编辑模式模版配置侧配置
import _ from 'lodash';
import {
  tabList,
  tabList2,
  colorList8,
  styleimg8,
  colorList10,
  styleimg10,
  colorList9,
  styleimg9,
  colorList4,
  colorList5,
  colorList6,
  styleimg4,
  styleimg5,
  colorList,
  colorInfo,
  fontSizeList,
  fontFamilyList,
  styleimg,
  colorList11,
  moduleType,
  SubunitList,
  moduleType4,
  SubunitList4,
  colorList15,
  SubunitList15,
  colorList13,
  SubunitList13,
  moduleType15,
  moduleType13,
  styleimg13,
  colorList17,
  SubunitList17,
  StyleImage17,
  SubunitList17List,
  SubunitExhibits,
  colorList22,
  StyleImage22,
  SubunitList22,
  SubunitList22List,
  Subunit22Exhibits,
} from '@/pages/templatePage/data';

const getGlobalTabList = (templateId?: number | string) => {
  //设置全局设置中各tab的显示或隐藏
  let arr = {
    colorShow: true, //颜色展示
    sizeShow: false, //字体选择展示
    styleShow: true, //风格样式
  };
  return arr;
};
const getStyleRandom = (array: any, type: number, isInit: boolean) => {
  //array 当前可选所有样式列表
  //type 当前选中的type
  //isInit 是否是第一次初始化
  //获取随机的下标
  let returnId = 0;
  if (isInit) {
    let index = Math.floor(Math.random() * array.length); //获取随机下标
    returnId = array[index].id;
  } else {
    let isExistence = array.findIndex((element) => {
      return element.id === type;
    });

    if (isExistence !== -1) {
      returnId = type;
    } else {
      let index = Math.floor(Math.random() * array.length); //获取随机下标
      returnId = array[index].id;
    }
  }
  // console.log(returnId);
  return returnId;
};
const getRandomModuleList = (data, templateId, isInit) => {
  //data原数据 templateId当前模版id
  //初始化单元逻辑

  let clonedObject = _.cloneDeep(data);
  clonedObject.forEach((element) => {
    if (templateId == 395740859879493) {
      //模版一组件切换逻辑
      if (element.children.length > 0) {
        if (element.children.length > 2) {
          element.type = getStyleRandom(moduleType.Subunit[6], element.type, isInit);
          // return moduleType.Subunit[6];
        } else {
          element.type = getStyleRandom(moduleType.Subunit[element.children.length - 1], element.type, isInit);
          // return moduleType.Subunit[];
        }
        // switch (element.children.length) {
        //   case 1:
        //     element.type = 12;
        //     break;
        //   case 2:
        //     element.type = getStyleRandom(moduleType.Subunit[1], element.type, isInit);
        //     break;
        //   case 3:
        //     element.type = getStyleRandom(moduleType.Subunit[2], element.type, isInit);
        //     break;
        //   case 4:
        //     element.type = getStyleRandom(moduleType.Subunit[3], element.type, isInit);
        //     break;
        //   case 5:
        //     element.type = getStyleRandom(moduleType.Subunit[4], element.type, isInit);
        //     break;
        //   case 6:
        //     element.type = getStyleRandom(moduleType.Subunit[5], element.type, isInit);
        //     break;
        //   default:
        //     element.type = getStyleRandom(moduleType.Subunit[6], element.type, isInit);
        //     break;
        // }
      } else if (element.children.length === 0 && element.showpieceTotal > 0) {
        element.type = getStyleRandom(moduleType.exhihits, element.type, isInit);
      } else {
        element.type = getStyleRandom(moduleType.preface, element.type, isInit);
      }
    }
    

    // SubunitList20List
  });

  // console.log(clonedObject, '生成的当前参数');
  return clonedObject;
};
const getLogoTabList = (templateId?: number | string) => {
  //设置logo设置中各tab的显示或隐藏
  let arr = {
    LogoShow: true, //logo上传功能
    banner: true, //轮播图功能
    wapBanner: true, //移动端轮播图上传
  };
  return arr;
};
const getEditRightTab = (templateId: number | string) => {
  //配置右侧侧边栏配置图表
  if (
    templateId == 395741054230597 ||
    templateId == 410276243316805 ||
    templateId == 666 ||
    templateId == 123456789 ||
    templateId == 99999 ||
    templateId == 1010 ||
    templateId == 888 ||
    templateId == 1997
  ) {
    return tabList2; //不包含首页样式
  } else {
    return tabList;
  }
};
const getGlobalColor = (templateId: number | string) => {
  let setting = {
    templateColorList: [],
    templateStyleimg: [],
  };
  console.log(templateId, '--------------templateId---------------------');
  //获取全局颜色以及图标样式表
  setting.templateColorList = colorList;
      setting.templateStyleimg = styleimg;
  return setting;
};
//获取单元样式配置列表
const getUnitStyle = (templateId: number | string) => {
  let unitList = [];

  unitList = SubunitList;
  return unitList;
};
const getChildType = (arr) => {
  let type = false;
  arr.forEach((element) => {
    if (element.children.length > 0) {
      type = true;
    }
  });
  return type;
};
export const getUnitStyleType = (templateId: number | string, e: any, index: number) => {
  //模版单元选择逻辑剥离
  if (e.children.length == 0) {
    if (e.children.length === 0 && e.showpieceTotal > 0) {
      return moduleType.exhihits;
    } else {
      return moduleType.preface;
    }
    return [];
  } else if (e.children.length > 2) {
    return moduleType.Subunit[6];
  } else {
    return moduleType.Subunit[e.children.length - 1];
  }
};
export {
  getRandomModuleList,
  getStyleRandom,
  getEditRightTab,
  getGlobalColor,
  getUnitStyle,
  getGlobalTabList,
  getLogoTabList,
};
